package com.bigdata.bookinfo.mapper;

import com.bigdata.bookinfo.pojo.KeyAndScore;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class CommentMaxMapper extends Mapper<LongWritable, Text, Text, KeyAndScore> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] line = value.toString().split("\t");
        if (line.length<2){
            return;
        }
        String title = line[0];
        String commentStr = line[1];
        double score;
        try {
            score = Double.parseDouble(commentStr);
        }catch (Exception e){
            return;
        }
        KeyAndScore keyAndScore = new KeyAndScore(title, score);
        context.write( new Text("1") , keyAndScore);
    }
}
